﻿/*******************************************************************   
 * 创建日期：2021.07.09 11:29:53  
 * 创 建 者：Administrator 
 * 功能描述：PlayerActor  
 *******************************************************************/
using System;

namespace Cars
{
    class PlayerActor : Actor
    {
        char m_Name;

        ConsoleColor m_Color;

        int m_Hp;

        public PlayerActor(char name, ConsoleColor color,int hP,Position ori)
        {
            m_Name = name;
            m_Color = color;
            m_Hp = hP;
            m_Position = ori;
        }

        public override void Draw()
        {
            DrawName(m_Position,m_Color,m_Name);
        }

        public override void Move(Position deltPos)
        {
            base.Move(deltPos);
            //不能超出窗口
            if (m_Position.x <= 0)
            {
                m_Position.x = 0;
            }
            if (m_Position.x >= Console.BufferWidth)
            {
                m_Position.x = Console.BufferWidth - 1;
            }
        }

        public void Hurt(int damageCount)
        {
            m_Hp -= damageCount;

            m_Hp = Math.Max(0, m_Hp);

            if(m_Hp == 0)
            {
                Dead();
            }
        }

        public override bool Dead()
        {
            DrawName(m_Position,ConsoleColor.Red,'X');
            return true;
        }

        private void DrawName(Position pos, ConsoleColor color,char name)
        {
            Console.ForegroundColor = color;
            Console.SetCursorPosition(pos.x, pos.y);
            Console.Write(name);
        }
    }
}
